package com.zpark.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.IOException;

/**
 * @PackageName: com.zpark.jsoup
 * @ClassName: Demo06
 * @Description: 假设favicon图像将是HTML文档的<head>部分中的第一个图像
 * @author: RZS
 * @date: 2021/8/15  23:20
 */
public class Demo06 {
    public static void main(String[] args) throws IOException {
        String favicon = "Not Found";
        Document document = Jsoup.connect("https://y.qq.com").get();
        Element element = document.head().select("link[href~=.*\\.(ico|png)]").first();
        if(element == null ){
            element = document.head().select("meta[itemprop=image]").first();
            if(element != null){
                favicon = element.attr("content");
            }
        }else {
            favicon = element.attr("href");
        }
        System.out.println(favicon);
    }
}
